package com.yun.algorithmproblem.huaweiod;

import java.util.LinkedList;

public class OD345 {
    public static void main(String[] args) {
//        Scanner sc = new Scanner(System.in);
//        String s = sc.nextLine();
        passWords("ABC<c89%000<");
    }

    private static void passWords(String s) {
        char[] ch = s.toCharArray();
        int num = 0;
        boolean res = false;
        int[] count = new int[4];
        StringBuilder sb = new StringBuilder();
        LinkedList<Integer> stack = new LinkedList<>();
        for (char c : ch) {
            if (c == '<') {
                if (sb.length() != 0) {
                    num--;
                    count[stack.pop()]--;
                    sb.setLength(sb.length() - 1);
                }
            } else {
                num++;
                int type = charType(c);
                stack.push(type);
                count[type]++;
                sb.append(c);
            }
        }
        if (count[0] > 0 && count[1] > 0 && count[2] > 0 && count[3] > 0 && num >= 8) {
            res = true;
        }
        sb.append(',');
        sb.append(res);
        System.out.println(sb);
    }

    private static int charType(char c) {
        if ('A' <= c && c <= 'Z') {
            return 0;
        }
        if ('a' <= c && c <= 'z') {
            return 1;
        }
        if ('0' <= c && c <= '9') {
            return 2;
        }
        return 3;
    }
}
